<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>

<?php

    $memberID = NULL;

//    if(isset($_REQUEST['btnGetCurrentLoans']))
//    {
//        $memberID = $_REQUEST['txtMemberID'];
//        
//        require 'lib/util.php';
//        
//        $memberCheckSql = "SELECT MemberID FROM usr_Member WHERE = " . $memberID;
//        $isValidMember = mysql_num_rows(executeSqlQuery($memberCheckSql));
//        
//        if($isValidMember == 1)
//        {
//            $_SESSION['memberID'] = $memberID;
//            $sql = "SELECT ID, MemberID, BookReferenceID, LendDate FROM inv_BOOK_LENDING WHERE MemberID = " . $memberID;
//            $rs = executeSqlQuery($sql);
//            $rowCount = mysql_num_rows($rs);
//        }
//        else
//        {
//            echo 'Invalid member ID.';
//        }
//    }
?>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <title></title>
    </head>
    <body>
        <?php
            session_start();
            include("/common/headerPage.php")
        ?>
        <div>
            <div id="menu_wrapper"></div>
            <div id="content_wrapper">
                <div id="fh_regular">Library Book Issue</div>
        <?php
            if (isset($_SESSION['UserName']))
            {
                echo "Logged<br><br><br>";
                
                echo "<a href=\"memStaff.php\">Staff</a><br>";
                echo "<a href=\"inventory/invHome.php\">Inventory</a><br>";
                echo "<a href=\"func/logoutHandler.php\">Finance</a><br>";
                echo "<a href=\"member/memHome.php\">Members</a><br>";
            }
            else
            {
                //echo "book search";
            }
        ?>
                <form action="" method="post">
                  <table width="75%" border="0" cellspacing="2" cellpadding="2" align="center">
                    <tr>
                        <td align="right" width="50%"><label class="text_reg">Member ID
                        <input type="text" name="txtMemberID" id="txtMemberID">
                      </label></td>
                      <td width="50%"><label class="text_reg">
                              <input type="submit" name="btnGetCurrentLoans" class="text_reg" id="btnGetCurrentLoans" value="Get">
                      </label></td>
                    </tr>
                  </table>
                </form>
                <br>
                <?php
                    if (isset($_REQUEST['btnGetCurrentLoans']))
                    {
                        $memberID = $_REQUEST['txtMemberID'];
                        
                        require 'lib/util.php';
                        
                        $sqlStaffMemberCheck = "SELECT lm.ID AS MemberID, si.StaffID AS StaffID, CONCAT(si.FirstName, ' ', si.LastName) AS MemberName FROM inv_LIBRARY_MEMBERS lm, usr_STAFF_INFO si WHERE si.StaffID = lm.StaffID AND lm.StaffID = " . $memberID;
                        $rsStaffMemberRecords = executeSqlQuery($sqlStaffMemberCheck);
                        $staffMembeRowCount = mysql_num_rows($rsStaffMemberRecords);
                        
                        $sqlStudentMemberCheck = "SELECT lm.ID AS MemberID, sti.StudentID AS StudentID, CONCAT(sti.FirstName, IF(sti.OtherName IS NOT NULL, CONCAT(' ' , sti.OtherName , ' '), ' '), sti.LastName) AS MemberName FROM inv_LIBRARY_MEMBERS lm, usr_STUDENTS_INFO sti WHERE sti.StudentID = lm.StudentID AND lm.StudentID = " . $memberID;
                        $rsStudentMemberRecords = executeSqlQuery($sqlStudentMemberCheck);
                        $studentMembeRowCount = mysql_num_rows($rsStudentMemberRecords);
                        
                        if ((!$staffMembeRowCount > 0) && (!$studentMembeRowCount > 0))
                        {
                            echo '<br>';
                            echo '<div id="infoBox">';
                                echo '<div id="error_text"> No Member Records are Found.</div>';
                            echo '</div>';
                            echo '<br>';
                        }
                        else
                        {
                            if ($staffMembeRowCount > 0)
                            {
                                ?>
                <form action="libMemberLoans.php" method="post">
                                    <table width="75%" align="center" cellpadding="2" cellspacing="2">
                                        <tr>
                                            <td class="text_reg">Staff ID</td>
                                            <td class="text_reg">Staff Name</td>
                                            <td class="text_reg"></td>
                                        </tr>
                                        
                                        <?php
                                            while ($rowStaff = mysql_fetch_array($rsStaffMemberRecords))
                                            {
                                                ?>
                                        <tr>
                                            <td class="text_reg"><?php echo $rowStaff['StaffID']; ?></td>
                                            <td class="text_reg"><?php echo $rowStaff['MemberName']; ?></td>
                                            <td class="text_reg"><input type="hidden" name="intMemberID" value="<?php echo $rowStaff['MemberID']; ?>"/><input type="submit" name="btnSelectMember" value="Select" /></td>
                                        </tr>
                                        
                                        <?php
                                            }
                                        ?>
                                    </table>
                                </form>                                
                                <?php
                            }
                            if ($studentMembeRowCount > 0)
                            {
                                ?>
                <br>
                <form action="libMemberLoans.php" method="post">
                                    <table width="75%" align="center" cellpadding="2" cellspacing="2">
                                        <tr>
                                            <td class="text_reg">Student ID</td>
                                            <td class="text_reg">Student Name</td>
                                            <td class="text_reg"></td>
                                        </tr>
                                        
                                        <?php
                                            while ($rowStudent= mysql_fetch_array($rsStudentMemberRecords))
                                            {
                                                ?>
                                        <tr>
                                            <td class="text_reg"><?php echo $rowStudent['StudentID']; ?></td>
                                            <td class="text_reg"><?php echo $rowStudent['MemberName']; ?></td>
                                            <td class="text_reg"><input type="hidden" name="intMemberID" value="<?php echo $rowStudent['MemberID']; ?>"/><input type="submit" name="btnSelectMember" value="Select" /></td>
                                        </tr>
                                        
                                        <?php
                                            }
                                        ?>
                                    </table>
                                </form>
                
                                <?php
                            }
                        }
                    }
                ?>
                
            </div>
        </div>
        <?php
            include ("/common/footerPage.php");
        ?>
    </body>
</html>
